package org.nowcoder.leetcode.BTree;

import java.util.ArrayList;
import java.util.List;

/**
 * Title  : 94. Binary Tree Inorder Traversal
 * Source : https://leetcode.cn/problems/binary-tree-inorder-traversal/
 * Author : XrazYang
 * Date   : 2023-09-05
 */

public class LeetCode_94 {
    private class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    private final List<Integer> result = new ArrayList<>();

    public List<Integer> inorderTraversal(TreeNode root) {
        if (root != null) {
            inorderTraversal(root.left);
            result.add(root.val);
            inorderTraversal(root.right);
        }
        return result;
    }
}
